﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Yatagan.IoC.ObjectBuilder
{
    internal class SingletonCreator : BaseObjectCreator
    {
        private static Dictionary<Type, object> _objects = new Dictionary<Type,object>();

        internal override object Create(Type type)
        {
            try 
	        {
                return (from v in _objects
                           where v.Key == type
                           select v).First().Value;
	        }
	        catch (Exception)
	        {
                NewCreator newCreator = new NewCreator();
                _objects[type] = newCreator.Create(type);
                return _objects[type];
	        }
        }
    }
}
